package bpm.dao.impl.user;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import bpm.domain.user.Privilege;

/**
 * 
 * @author ZhaoWangLong Sep 20, 2011
 *
 */
public class PrivilegeBatchPreparedStatementSetter implements BatchPreparedStatementSetter {
	private List<Privilege> privileges;
	public PrivilegeBatchPreparedStatementSetter(List<Privilege> privileges){
		this.privileges=privileges;
	}
	public int getBatchSize() {
		return privileges.size();
	}
	public void setValues(PreparedStatement ps, int i) throws SQLException {
		ps.setString(1, privileges.get(i).getId());
		ps.setString(2, privileges.get(i).getRole()==null?null:privileges.get(i).getRole().getId());
		ps.setString(3, privileges.get(i).getRole()==null?null:(privileges.get(i).getRole().getGroupType()==null?null:
			privileges.get(i).getRole().getGroupType().getId()));
		ps.setString(4, privileges.get(i).getResourceType()==null?null:privileges.get(i).getResourceType().name());
		ps.setString(5, privileges.get(i).getResourceId());
		ps.setString(6, privileges.get(i).getResourceScope());
		ps.setString(7, privileges.get(i).getResourceScopeType()==null?null:privileges.get(i).getResourceScopeType().name());
		ps.setString(8, privileges.get(i).isConstant()?"1":"0");
		ps.setString(9, privileges.get(i).isDirect()?"1":"0");
		ps.setString(10, privileges.get(i).getDescription());
	}
}
